package com.qf.controller;

import com.qf.entity.Order;
import com.qf.entity.User;
import com.qf.service.OrderService;
import com.qf.service.UserService;
import com.qf.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api")

public class LikeController {
    @Autowired
    private UserService userService;

    @Autowired
    private OrderService orderService;

    @GetMapping("/findUserByUsernameLike")
    public R findUserByUsernameLike(String username) {
        try {
            List<User> users = userService.findByUsernameLike(username);
            return R.ok(users);
        } catch (Exception e) {
            return R.fail();
        }
    }
    @GetMapping("/findOrderByProductNameLike")
    public R findByOrdernameLike(Integer userId, String productName) {
        try {
            List<Order> orders = orderService.findByOrdernameLike(userId, productName);
            return R.ok(orders);
        } catch (Exception e) {
            return R.fail();
        }
    }
}
